$(function(){
	$.ajax({
	    type:"post",
	    url:url+'/profile/convertpage.html?token='+token,
	    async:false,
	    data:{'token':token},
	    dataType:'json',
	    success:function(result){
	        if(result.status === "0001"){
	        	var data=result.data;
	        	$(".hcg_wa").html(data.hcg_wa);
	        	$(".cash_wa").html(data.cash_wa);
	        	$(".care_wa").html(data.care_wa);
	        	
	        	$(".cash_hcg").attr("data1",data.cash_hcg);
	        	$(".care_cash").attr("data1",data.care_cash);
	        }else{
	            isErr(result);
	        }
	    },
		error:function(){
			layer.msg("响应失败");
		}
	})
	
//	切换
	$(".myexch_radio").on("change",function(){
		var conver_num=$(".conver_num").val();
		if($(".myexch_radio:checked").attr("data") == "1"){
			$(".kkl1").html("节点钱包");
			$(".kkl2").html("节点资产");
		}else{
			$(".kkl1").html("SDC余额");
			$(".kkl2").html("节点钱包");
		}
		if(conver_num != ""){
			$(".conver_num_1").html(conver_num*($(".myexch_radio:checked").attr("data1")));
		}
//		初始化
		$(".sh_list").html("");
		$('.notMore').css('display',"none");
		$(document).scrollTop(0);
		p=1;
		list_qb(p);
	})
	
//	输入框
	$(".conver_num").on("keyup",function(){
		if($(this).val() != ""){
			$(".conver_num_1").html(($(this).val())*($(".myexch_radio:checked").attr("data1")));
		}
	})
	
	
	var p=1;
	function list_qb(p){
		var type=$(".myexch_radio:checked").attr("data");
		var d={};
		d.page=p;
		d.type=type;
		d.token=token;
		$.ajax({
		    type:"post",
		    url:url+'/profile/converrecord.html?token='+token,
		    async:false,
		    data:d,
		    dataType:'json',
		    success:function(result){
		        if(result.status === "0001"){
		        	var data=result.data;
		        	var html = '';
		        	for(var i in data){
		        		html += '<li class="sh_item"><div class="shitem_le">';
						html += '<p class="shitem_let">'+data[i].input_amount+'</p>';
						html += '<p class="shitem_let">'+data[i].created_at+'</p></div>';
						html += '<p class="shitem_title">'+data[i].get_amount+'</p></li>';
		        	}
		        	if (html == "" || data.length < 10) {
						$('.notMore').css('display',"block")
					}
		        	$(".sh_list").append(html);
		        }else{
		            isErr(result);
		        }
		    },
			error:function(){
				layer.msg("响应失败");
			}
		})
	}
	list_qb(1);
	//	下拉加载更多
	$(window).scroll(function() {
		if ($(document).scrollTop() >= $(document).height() - $(window).height() - 70) {			
		// console.log('我到底了');
			if ($('.notMore').css('display') != "block") {
				p++;
				list_qb(p);
			}
		}
	})
	
	
//	兑换按钮
var prevent_repetition=true;
	$(".exchange_btn").on("click",function(){
		if(prevent_repetition){
			prevent_repetition=false;
			var conver_num=$(".conver_num").val();
			var pay_pwd=$(".pay_pwd").val();
			var type=$(".myexch_radio:checked").attr("data");
			if(!conver_num){
				layer.msg("请输入兑换数量");
				prevent_repetition=true;
				return false;
			}
			if(!pay_pwd){
				layer.msg("请输入安全密码");
				prevent_repetition=true;
				return false;
			}
			var d={};
			d.token=token;
			d.conver_num=conver_num;
			d.pay_pwd=pay_pwd;
			d.type=type;
			$.ajax({
			    type:"post",
			    url:url+'/profile/doconver.html?token='+token,
			    async:false,
			    data:d,
			    dataType:'json',
			    success:function(result){
			        if(result.status == "0001"){
			        	layer.msg(result.message);
//						初始化
						$(".sh_list").html("");
						$('.notMore').css('display',"none");
						$(document).scrollTop(0);
						$(".pay_pwd").val("");
						p=1;
						list_qb(p);
			        }else{
			            isErr(result);
			        }
			    },
				error:function(){
					layer.msg("响应失败");
				},
				complete: function() {
					prevent_repetition = true;
				}
			})
		}
	})
})
